package com.zxbg.dao;

import com.zxbg.domain.AppCategory;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

public interface AppCategoryDao {
    @Select("select * from app_category where tenant_id = #{tenant_id} order by `order`")
    public List<AppCategory> getAllCategory(Integer tenant_id);

    @Insert("insert into app_category values(null, #{category_name_zh}, #{category_name_en}, #{show}, #{add_time}, #{order},#{tenant_id})")
    public int addCategory(AppCategory appCategory);

    @Delete("delete from app_category where category_id = #{category_id}")
    public int deleteCategory(Integer category_id);

    @Update("update app_category set category_name_zh = #{category_name_zh}, category_name_en = #{category_name_en}, `show` = #{show} where category_id = #{category_id}")
    public int updateCategory(AppCategory appCategory);

    @Select("select category_id from app_category where `order` = #{order} and tenant_id = #{tenant_id}")
    public Integer getCategoryIdByOrder(@Param("order") Integer order, @Param("tenant_id") Integer tenant_id);

    @Update("update app_category set `order` = #{newIndex} where `order` = #{oldIndex} and tenant_id = #{tenant_id}")
    public int updateCategoryOrderByOrder(@Param("oldIndex") Integer oldIndex, @Param("newIndex") Integer newIndex, @Param("tenant_id") Integer tenant_id);

    @Update("update app_category set `order` = #{newIndex} where category_id = #{category_id}")
    public int updateCategoryOrderByCategoryId(@Param("category_id") Integer category_id, @Param("newIndex") Integer newIndex);

    @Select("select * from app_category where tenant_id = #{tenant_id} and `show` = 1")
    public List<AppCategory> getActiveCategory(Integer tenant_id);
}
